<?

function google_extract_places_search_results($goog) {

    $places = array();
	
    $temp = $goog['predictions'];
	
	if (is_array($temp)) {
	    $c = 0;
		foreach ($temp as $slice) {
            if ($c++ > 2) break;
            $s  = str_ireplace(", United States", "", $slice['description']);
			array_push($places, $s);
		}
	
    	return $places;
	
	} else {
		return array("-1");
	}
}



$APPKEY = "AIzaSyBQZ7w1bdCtYlJ1XYHCw6CWhuwUybKs6fs";
$SEARCH = "https://maps.googleapis.com/maps/api/place/autocomplete/json?types=geocode&language=en&sensor=true&key=".$APPKEY."&input=".urlencode($_GET['search']);

 
$reply = json_decode(file_get_contents($SEARCH), true);


echo json_encode(google_extract_places_search_results($reply));



?>
